package painting;

import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;



import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics; 
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseMotionAdapter;
import java.util.ArrayList;

public class Painter  extends JPanel{
    




   // RedSquare redSquare = new RedSquare();
    
    ArrayList<RedSquare> squares = new ArrayList<RedSquare>();
    ArrayList<BlackSquare> blackSquares = new ArrayList<BlackSquare>();
private JFrame f;

    public Painter(JFrame f) {
    	this.f = f;

        setBorder(BorderFactory.createLineBorder(Color.black));

//        addMouseListener(new MouseAdapter(){
//            public void mousePressed(MouseEvent e){
//                //moveSquare(e.getX(),e.getY());
//                squares.add(new RedSquare(e.getX(),e.getY()));
//                paint();
//            }
//        });
//
//        addMouseMotionListener(new MouseAdapter(){
//            public void mouseDragged(MouseEvent e){
//               // moveSquare(e.getX(),e.getY());
//            	blackSquares.add(new BlackSquare(e.getX(),e.getY()));
//                paint();
//            }
//        });

    }
    
    public void addRedSquare(int x, int y){
    	squares.add(new RedSquare(x,y));
    	paint();
    }
    
    public void addBlackSquare(int x, int y){
    	blackSquares.add(new BlackSquare(x,y));
    	paint();
    }

    protected void paint() {
		for(RedSquare redSquare : squares){
			redSquare.paintSquare(f.getGraphics());
		}
		
		for(BlackSquare blackSquare : blackSquares){
			blackSquare.paintSquare(f.getGraphics());
		}	
	}


//        final int OFFSET = 1;


    public Dimension getPreferredSize() {
        return new Dimension(1000,1000);
    }
    
    public void paintComponent(Graphics g) {
        super.paintComponent(g);       
        g.drawString("The mapping of the robot!",10,20);
    }  
}

class RedSquare{

    private int xPos = 50;
    private int yPos = 50;
    private int width = 5;
    private int height = 5;

    public RedSquare(int x, int y) {
		xPos = x;
		yPos = y;
	}

	public void setX(int xPos){ 
        this.xPos = xPos;
    }

    public int getX(){
        return xPos;
    }

    public void setY(int yPos){
        this.yPos = yPos;
    }

    public int getY(){
        return yPos;
    }

    public int getWidth(){
        return width;
    } 

    public int getHeight(){
        return height;
    }

    public void paintSquare(Graphics g){
        g.setColor(Color.RED);
        g.fillRect(xPos,yPos,width,height);
        g.setColor(Color.BLACK);
        g.drawRect(xPos,yPos,width,height);  
    }
    
   
    }

class BlackSquare{

    private int xPos = 50;
    private int yPos = 50;
    private int width = 5;
    private int height = 5;

    public BlackSquare(int x, int y) {
		xPos = x;
		yPos = y;
	}

	public void setX(int xPos){ 
        this.xPos = xPos;
    }

    public int getX(){
        return xPos;
    }

    public void setY(int yPos){
        this.yPos = yPos;
    }

    public int getY(){
        return yPos;
    }

    public int getWidth(){
        return width;
    } 

    public int getHeight(){
        return height;
    }

    public void paintSquare(Graphics g){
        g.setColor(Color.BLACK);
        g.fillRect(xPos,yPos,width,height);
        g.setColor(Color.BLACK);
        g.drawRect(xPos,yPos,width,height);  
    }
}
